package com.twu.biblioteca;

/**
 * Created by sarahc on 1/15/14.
 */
public class UserManager {

    private Library library;
    private Customer currentUser;

    public UserManager(Library library){
        this.library = library;
        this.currentUser = null;
    }

    public boolean login(String libraryNumber, String password){
        for (Customer customer : library.getCustomers()){
            if (customer.getLibraryNumber().equals(libraryNumber) &&
                    customer.getPassword().equals(password)){
                currentUser = customer;
                return true;
            }
        }
        return false;
    }

    public Customer getCurrentUser(){
        return this.currentUser;
    }

    public String getUserInfo(){
        StringBuilder userInfo = new StringBuilder();
        userInfo.append("-USER INFORMATION-\n");
        userInfo.append("Library Number: " + currentUser.getLibraryNumber() + "\n");
        userInfo.append("Name: " + currentUser.getName() + "\n");
        userInfo.append("Email: " + currentUser.getEmail() + "\n");
        userInfo.append("Phone: " + currentUser.getPhone() + "\n");

        return userInfo.toString();
    }

}
